import os
import allure
import pytest
from config.config import BASE_DIR
from util.assert_util import assert_csv_to_db_with_details_with_allure, assert_equal_with_allure
from util.file_util import read_json_file
from util.upload_etl_data_util import wait_for_file_processing

@allure.feature("ETL")
@allure.story("Smoke Test")
class TestcaseEtl:
    
    @pytest.mark.parametrize("desc, queue_name, csv_file_path, expected_result", read_json_file(os.path.join(BASE_DIR, "data", "etl", "test_data_param", "etl_smoke_test_data.json")))
    def testcase_upload_historical_pl_all_fields(self,setup_wf_upload_api, desc, queue_name, csv_file_path, expected_result):
        allure.title(desc)
        # test step
        resp = setup_wf_upload_api.upload_file_to_queue(queue_name, csv_file_path)

        file_id = resp.get("files")[0].get("fileId")
        # wait for file processing
        upload_status = wait_for_file_processing(file_id)
        
        # expected result
        expected_upload_status = expected_result.get("upload_status")
        expected_db_table_name = expected_result.get("db_table_name")
        assert_equal_with_allure("Upload status", upload_status, expected_upload_status)
        assert_csv_to_db_with_details_with_allure(csv_file_path, expected_db_table_name, file_id, "ETL")
        
        
    




